﻿using DI;
using Repositories;
using StructureMap;
using StructureMap.Pipeline;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Transactions;

namespace Tests.Helpers
{
    public class ControllerHelper<TController>
    {       
        private IContainer container;

        private void CreateNestedController()
        {
            container = Bootstrapper.Container.GetNestedContainer();
            container.Configure(x =>
            {
                x.For<TController>().Transient();
            });
        }

        private void ClearNestedController()
        {
            container.Dispose();
            container = null;
        }        

        public void Initialize()
        {                                                        
            CreateNestedController();            
        }

        public void Cleanup()
        {                      
            ClearNestedController();                                  
        }

        public TController GetController()
        {
            return (TController)container.TryGetInstance(typeof(TController));
        }
    }
}
